var request = require('../../utils/request.js');

Page({
    data: {
        formList: [

        ],
        statusDict: {
            '2': 'status-green',
            '1': 'status-blue',
            '-1': 'status-red',
            '0': 'status-yellow'
        }
    },
    page: 1,
    getList() {
        wx.showLoading({
            title: '拼命加载中',
            mask: true
        })
        console.log(this.page)
        let that = this
        request.GET('/api/list/all?page=' + this.page).then(
            function (res) {
                console.log(res)
                if (res.statusCode != 200) return
                let list = res.data.results
                if (list.length != 0) {
                    that.page++
                }
                list = list.map((item) => {
                    time = item.time.split('T')[0]
                    item.time = time
                    return item
                })
                that.setData({
                    formList: [...that.data.formList, ...list]
                })
                qq.stopPullDownRefresh()
            }
        )
    },
    onLoad() {
        this.getList()
    },
    onReachBottom() {
        this.getList()
    },

    onPullDownRefresh() {
        this.setData({
            formList: []
        })
        this.page = 1
        this.getList()
        qq.hideLoading()
    },

    onShareAppMessage: function () {
        qq.showShareMenu({
            showShareItems: ['qq', 'qzone', 'wechatFriends', 'wechatMoment']
        })
    },

})